﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Com.Mapabc.Maps.Api.BaseTypes;

namespace MapABCAPI_WP7.Samples
{
    public partial class GetMapInfo : PhoneApplicationPage
    {
        public GetMapInfo()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 获取地图中心点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Get_Center(object sender, GestureEventArgs e)
        {
            MLngLat center =  map.Center;
            CenterLngX.Text = String.Format("中心点经度: {0}", Math.Round(center.LngX, 3));
            CenterLatY.Text = String.Format("中心点纬度: {0}", Math.Round(center.LatY, 3));
            Pivot.SelectedIndex = 1;//显示效果
            Hidden();
            CenterLngX.Visibility = System.Windows.Visibility.Visible;
            CenterLatY.Visibility = System.Windows.Visibility.Visible;

        }
        /// <summary>
        /// 获取地图zoom
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Get_Zoom(object sender, GestureEventArgs e)
        {
            double zoom = map.Zoom;
            CenterLngX.Text = zoom.ToString();
            CenterLatY.Text = "";
            Pivot.SelectedIndex = 1;//显示效果
            Hidden();
            CenterLngX.Visibility = System.Windows.Visibility.Visible;
            CenterLatY.Visibility = System.Windows.Visibility.Visible;
        }
        /// <summary>
        /// 获取地图视野范围
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Get_MapSize(object sender, GestureEventArgs e)
        {
            Size mapsize = map.MapSize;
            CenterLngX.Text = mapsize.ToString();
            CenterLatY.Text = "";
            Pivot.SelectedIndex = 1;//显示效果
            Hidden();
            CenterLngX.Visibility = System.Windows.Visibility.Visible;
            CenterLatY.Visibility = System.Windows.Visibility.Visible;
        }
        /// <summary>
        /// 获取地图视野西南东北角坐标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MgetLngLatBounds(object sender, GestureEventArgs e)
        {
            getMapLngLatBounds();
            Pivot.SelectedIndex = 1;//显示效果
            Hidden();
            swX.Visibility = System.Windows.Visibility.Visible;
            swY.Visibility = System.Windows.Visibility.Visible;
            neX.Visibility = System.Windows.Visibility.Visible;
            neY.Visibility = System.Windows.Visibility.Visible;
            button1.Visibility = System.Windows.Visibility.Visible;
        }
        private void getMapLngLatBounds()
        {
            MLngLatBounds lnglatbounds = map.LngLatBounds;
            swX.Text = (lnglatbounds.SouthWest.LngX).ToString();
            swY.Text = (lnglatbounds.SouthWest.LatY).ToString();
            neX.Text = (lnglatbounds.NorthEast.LngX).ToString();
            neY.Text = (lnglatbounds.NorthEast.LatY).ToString();
        }
        private void LngLatBounds(object sender, RoutedEventArgs e)
        {
            getMapLngLatBounds();
        }
        /// <summary>
        /// 隐藏所有的控件
        /// </summary>
        private void Hidden()
        { 
            CenterLngX.Visibility = System.Windows.Visibility.Collapsed;
            CenterLatY.Visibility = System.Windows.Visibility.Collapsed;
            swX.Visibility = System.Windows.Visibility.Collapsed;
            swY.Visibility = System.Windows.Visibility.Collapsed;
            neX.Visibility = System.Windows.Visibility.Collapsed;
            neY.Visibility = System.Windows.Visibility.Collapsed;
            button1.Visibility = System.Windows.Visibility.Collapsed;
        }
        /// <summary>
        /// 重写后退键
        /// </summary>
        /// <param name="e"></param>
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (Pivot.SelectedIndex == 1)
            {
                e.Cancel = true;
                Pivot.SelectedIndex = 0;
            }
        }   
    }
}